//
//  MyOrderGoodsItemCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2018/1/11.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "MyOrderGoodsItemCell.h"

@interface MyOrderGoodsItemCell ()
@property (weak, nonatomic) IBOutlet UIImageView *leftImageView;
@property (weak, nonatomic) IBOutlet UILabel *topLabel;
@property (weak, nonatomic) IBOutlet UILabel *twoLabel;
@property (weak, nonatomic) IBOutlet UILabel *threeLabel;
@property (weak, nonatomic) IBOutlet UILabel *fourLabel;
@property (weak, nonatomic) IBOutlet UILabel *leftLabel;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *middleMargin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;

@property (weak, nonatomic) IBOutlet UILabel *priceLabe;
@property (weak, nonatomic) IBOutlet UILabel *guiGeLabel;

@property (weak, nonatomic) IBOutlet UILabel *countLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomBgViewH;
@property (weak, nonatomic) IBOutlet UIButton *itemTwoBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *itemTwoBtnW;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightBtnW;

@end

@implementation MyOrderGoodsItemCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.middleMargin.constant = 0;
    
    self.bottomMargin.constant = 0;
    
    self.leftLabel.font = MYFONT(14);
    
    self.leftLabel.textColor = darkGray;
    
    self.topLabel.font = MYFONT(14);
    
    self.twoLabel.font = MYFONT(13);
    
    self.twoLabel.textColor = darkGray;
    
    self.twoLabel.text = @"价格:";
    
    self.threeLabel.font = MYFONT(13);
    
    self.threeLabel.textColor = darkGray;
    
    self.threeLabel.text = @"规格:";
    
    self.fourLabel.font = MYFONT(13);
    
    self.priceLabe.font = MYFONT(13);
    self.guiGeLabel.font = MYFONT(13);
    self.countLabel.font = MYFONT(13);

    self.fourLabel.textColor = darkGray;
    
    self.fourLabel.text = @"数量:";
    
    self.rightBtn.titleLabel.font = MYFONT(14);
    
    self.rightBtn.backgroundColor = [UIColor whiteColor];
    
    self.rightBtn.layer.cornerRadius = 3;
    self.rightBtn.layer.masksToBounds = YES;
    
    
    self.itemTwoBtn.titleLabel.font = MYFONT(14);
    
    self.itemTwoBtn.backgroundColor = [UIColor whiteColor];
    
    self.itemTwoBtn.layer.cornerRadius = 3;
    self.itemTwoBtn.layer.masksToBounds = YES;
    
    [self.rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    
    [self.itemTwoBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.itemTwoBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];

    self.rightBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.rightBtn.layer.borderWidth = 0.6;
    
    self.itemTwoBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.itemTwoBtn.layer.borderWidth = 0.6;
    // Initialization code
}


- (void)setModel:(MyOrderItemsModel *)model{
    _model = model;
    
    self.itemTwoBtn.hidden = YES;
    
    self.topLabel.text = _model.goods_name;
    
//    self.rightBtn.backgroundColor = [UIColor whiteColor];
    
    [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:_model.pic_cover_small] placeholderImage:nil];
    
    self.priceLabe.text = [NSString stringWithFormat:@"%@P",_model.price];
    
    self.countLabel.text = [NSString stringWithFormat:@"%@件",_model.num];
    
    self.guiGeLabel.text = @"";
    
    //    -1退款   0待付款 1待发货 2已发货  3已收货  5已关闭
    if ([_model.order_status isEqualToString:@"-1"]) {
        self.rightBtn.hidden = NO;
        self.leftLabel.hidden = NO;
        
        
        if ([_model.refund_status isEqualToString:@"0"]) {
            [self.rightBtn setTitle:@"退款/退货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"退款/退货" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"1"]){
            [self.rightBtn setTitle:@"买家申请退款" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"买家申请退款" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"2"]){
            [self.rightBtn setTitle:@"卖家同意退货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"卖家同意退货" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"3"]){
            [self.rightBtn setTitle:@"等待卖家确认收货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"等待卖家确认收货" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"4"]){
            [self.rightBtn setTitle:@"卖家已收货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"卖家已收货" forState:UIControlStateHighlighted];
        }else if ([_model.refund_status isEqualToString:@"5"]){
            [self.rightBtn setTitle:@"退款已成功" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"退款已成功" forState:UIControlStateHighlighted];
        }else{
            
            
            
        }
        
        
        
    } else if ([_model.order_status isEqualToString:@"0"]){
        self.rightBtn.hidden = YES;
        self.leftLabel.hidden = YES;
        
        
    }else if ([_model.order_status isEqualToString:@"1"]){
  
        self.rightBtn.hidden = NO;
        self.leftLabel.hidden = NO;
        
        if ([_model.shipping_status isEqualToString:@"1"]) {
            self.leftLabel.text = @"已发货";
        } else {
            self.leftLabel.text = @"待发货";

        }

        if ([_model.refund_status isEqualToString:@"0"]) {
            [self.rightBtn setTitle:@"退款/退货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"退款/退货" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"1"]){
            [self.rightBtn setTitle:@"买家申请退款" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"买家申请退款" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"2"]){
            [self.rightBtn setTitle:@"等待买家退货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"等待买家退货" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"3"]){
            [self.rightBtn setTitle:@"等待卖家确认收货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"等待卖家确认收货" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"4"]){
            [self.rightBtn setTitle:@"卖家已收货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"卖家已收货" forState:UIControlStateHighlighted];
        }else if ([_model.refund_status isEqualToString:@"5"]){
            [self.rightBtn setTitle:@"退款已成功" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"退款已成功" forState:UIControlStateHighlighted];
        }else{
            
            
            
        }
        
        
    }else if ([_model.order_status isEqualToString:@"2"]){
        self.rightBtn.hidden = NO;
        self.leftLabel.hidden = NO;
        
        self.leftLabel.text = @"已发货";
        
        if ([_model.refund_status isEqualToString:@"0"]) {
            [self.rightBtn setTitle:@"退款/退货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"退款/退货" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"1"]){
            [self.rightBtn setTitle:@"买家申请退款" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"买家申请退款" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"2"]){
            [self.rightBtn setTitle:@"等待买家退货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"等待买家退货" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"3"]){
            [self.rightBtn setTitle:@"等待卖家确认收货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"等待卖家确认收货" forState:UIControlStateHighlighted];
        } else if ([_model.refund_status isEqualToString:@"4"]){
            [self.rightBtn setTitle:@"卖家已收货" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"卖家已收货" forState:UIControlStateHighlighted];
        }else if ([_model.refund_status isEqualToString:@"5"]){
            [self.rightBtn setTitle:@"退款已成功" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"退款已成功" forState:UIControlStateHighlighted];
        }else{
            
            
            
        }
        
        
    }else if ([_model.order_status isEqualToString:@"3"]){
        self.rightBtn.hidden = NO;
        self.leftLabel.hidden = NO;
        
        self.leftLabel.text = @"已发货";
        
        if ([_model.is_evaluate isEqualToString:@"0"]) {
            self.rightBtn.hidden = NO;
            [self.rightBtn setTitle:@"我要评价" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"我要评价" forState:UIControlStateHighlighted];
        } else{
            self.rightBtn.hidden = NO;
            [self.rightBtn setTitle:@"已评价" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"已评价" forState:UIControlStateHighlighted];
//            self.rightBtn.backgroundColor = [UIColor colorWithHexString:@"#cccccc"];;
        }
        
        
        if ([_model.refund_status isEqualToString:@"5"]) {
            self.itemTwoBtn.hidden = NO;
            [self.itemTwoBtn setTitle:@"退款已成功" forState:UIControlStateNormal];
            [self.itemTwoBtn setTitle:@"退款已成功" forState:UIControlStateHighlighted];
        }
        
   
        
        
    }else if ([_model.order_status isEqualToString:@"5"]){
        self.rightBtn.hidden = YES;
        self.leftLabel.hidden = YES;
        
        if ([_model.refund_status isEqualToString:@"5"]){
            self.rightBtn.hidden = NO;
   
            [self.rightBtn setTitle:@"退款已成功" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"退款已成功" forState:UIControlStateHighlighted];
        }
        
    }else{
        
        self.rightBtn.hidden = NO;
        self.leftLabel.hidden = NO;
    }
    
    
    
    
    if (self.rightBtn.hidden == YES && self.leftLabel.hidden == YES) {
        
        self.bottomBgViewH.constant = 8;

    } else {
        
        self.bottomBgViewH.constant = 44;

    }
    
    
    NSString *btn1 = self.rightBtn.currentTitle;
    NSString *btn2 = self.itemTwoBtn.currentTitle;
    
    CGSize size1 = [btn1 sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MYFONT(14), NSFontAttributeName, nil]];


    CGSize size2 = [btn2 sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MYFONT(14), NSFontAttributeName, nil]];

    
    self.rightBtnW.constant = size1.width + 12;
    
    self.itemTwoBtnW.constant = size2.width + 12;

    
}
//- (void)btnDidClickWith:(NSString *)title;


- (IBAction)rightBtnDidTap:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(btnDidClickWith:index:)]) {
        [self.delegate btnDidClickWith:sender.currentTitle index:self.index];
    }
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
